package ModelLayer;

import java.util.ArrayList;
/**
 * Write a description of class Person here.
 * 
 * @author (Brian, Jesper, Jesper og  Hoang) 
 * @version (a version number or a date)
 */
public class VareContainer
{
    //Instance variabler
    private ArrayList<Vare> vare;
    public static VareContainer instance;
  
    //Constructor
    private VareContainer()
    {
        vare = new ArrayList<Vare>();
    }
    
    //Singleton
    public static VareContainer getVareContainer()
    {
        if(instance == null)
        {
            instance = new VareContainer();
        }
        
        return instance;
    }
    
    //Metode til at tilføje vare
    public void addVare(Vare _vare)
    {
        vare.add(_vare);
    }
    
    //Metode til at søge efter ID
    public Vare searchById(int _id)
    {
        Vare retVare = null;
        int index = 0;
        boolean found = false;
        
        while(index < vare.size() && !found)
        {
            Vare currVare = vare.get(index);
            if(currVare.getId() == _id)
            {
                retVare = currVare;
                found = true;
            }
            else
            {
                index++;
            }
        }
        
        return retVare;
    }
    
    //Metode til at vise alle vare
    public ArrayList<Vare> getAllVare()
    {
        return vare;
    }
    
    //Metode til at slette vare
    public void deleteVare(Vare _vare)
    {
        vare.remove(_vare);
    }
}
